package reflect;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Person p=new Person();
        System.out.println(p);

        /*
        反射机制实例化
        1获取对应的类对象
        2通过类对象的newInstance()方法实例化
         */
        Class cls=Person.class;
        Object obj=cls.newInstance();
        System.out.println(obj);

        /*
        java.util.ArrayList
        java.util.HashMap
        java.util.Date(日期类，实例化后输出的是当前系统时间)
        reflect.Person
         */


        Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个类的完全限定名");
        String className=sc.nextLine();

        Class cls1=Class.forName(className);
        //newInstance()方法会调用类的公开的无参构造器
        Object obj1=cls1.newInstance();
        System.out.println(obj1);
    }

    @Override
    public String toString() {
        return "ReflectDemo2{}";
    }
}
